<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActiveSupport::Cache</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/github.css" type="text/css" media="screen" />
<script src="../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Module</span> 
            ActiveSupport::Cache 
            
        </h1>
        <ul class="files">
            
            <li><a href="../../files/activesupport/lib/active_support/cache_rb.html">activesupport/lib/active_support/cache.rb</a></li>
            
            <li><a href="../../files/activesupport/lib/active_support/cache/file_store_rb.html">activesupport/lib/active_support/cache/file_store.rb</a></li>
            
            <li><a href="../../files/activesupport/lib/active_support/cache/mem_cache_store_rb.html">activesupport/lib/active_support/cache/mem_cache_store.rb</a></li>
            
            <li><a href="../../files/activesupport/lib/active_support/cache/memory_store_rb.html">activesupport/lib/active_support/cache/memory_store.rb</a></li>
            
            <li><a href="../../files/activesupport/lib/active_support/cache/null_store_rb.html">activesupport/lib/active_support/cache/null_store.rb</a></li>
            
            <li><a href="../../files/activesupport/lib/active_support/cache/strategy/local_cache_rb.html">activesupport/lib/active_support/cache/strategy/local_cache.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<p>See <a href="Cache/Store.html">ActiveSupport::Cache::Store</a> for
documentation.</p>

    </div>
  


  


  
  


  
    <!-- Namespace -->
    <div class="sectiontitle">Namespace</div>
    <ul>
      
        <li>
          <span class="type">MODULE</span>
          <a href="Cache/Strategy.html">ActiveSupport::Cache::Strategy</a>
        </li>
      
        <li>
          <span class="type">CLASS</span>
          <a href="Cache/FileStore.html">ActiveSupport::Cache::FileStore</a>
        </li>
      
        <li>
          <span class="type">CLASS</span>
          <a href="Cache/MemCacheStore.html">ActiveSupport::Cache::MemCacheStore</a>
        </li>
      
        <li>
          <span class="type">CLASS</span>
          <a href="Cache/MemoryStore.html">ActiveSupport::Cache::MemoryStore</a>
        </li>
      
        <li>
          <span class="type">CLASS</span>
          <a href="Cache/NullStore.html">ActiveSupport::Cache::NullStore</a>
        </li>
      
        <li>
          <span class="type">CLASS</span>
          <a href="Cache/Store.html">ActiveSupport::Cache::Store</a>
        </li>
      
    </ul>
  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>E</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Cache.html#method-c-expand_cache_key">expand_cache_key</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>L</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Cache.html#method-c-lookup_store">lookup_store</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    
      <!-- Section constants -->
      <div class="sectiontitle">Constants</div>
      <table border='0' cellpadding='5'>
        
          <tr valign='top'>
            <td class="attr-name">UNIVERSAL_OPTIONS</td>
            <td>=</td>
            <td class="attr-value">[:namespace, :compress, :compress_threshold, :expires_in, :race_condition_ttl]</td>
          </tr>
          
            <tr valign='top'>
              <td>&nbsp;</td>
              <td colspan="2" class="attr-desc"><p>These options mean something to all cache implementations. Individual cache
implementations may support additional options.</p></td>
            </tr>
          
        
      </table>
    


    


    <!-- Methods -->
    
      <div class="sectiontitle">Class Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-c-expand_cache_key">
            
              <b>expand_cache_key</b>(key, namespace = nil)
            
            <a href="Cache.html#method-c-expand_cache_key" name="method-c-expand_cache_key" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Expands out the <code>key</code> argument into a key that can be used for
the cache store. Optionally accepts a namespace, and all keys will be
scoped within that namespace.</p>

<p>If the <code>key</code> argument provided is an array, or responds to
<code>to_a</code>, then each of elements in the array will be turned into
parameters/keys and concatenated into a single key. For example:</p>

<pre class="ruby"><span class="ruby-identifier">expand_cache_key</span>([:<span class="ruby-identifier">foo</span>, :<span class="ruby-identifier">bar</span>])               <span class="ruby-comment"># =&gt; &quot;foo/bar&quot;</span>
<span class="ruby-identifier">expand_cache_key</span>([:<span class="ruby-identifier">foo</span>, :<span class="ruby-identifier">bar</span>], <span class="ruby-string">&quot;namespace&quot;</span>)  <span class="ruby-comment"># =&gt; &quot;namespace/foo/bar&quot;</span>
</pre>

<p>The <code>key</code> argument can also respond to <code>cache_key</code> or
<code>to_param</code>.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-expand_cache_key_source')" id="l_method-c-expand_cache_key_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/3182295ce2fa01b02cb9af0b977a9cf83cc5d9aa/activesupport/lib/active_support/cache.rb#L79" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-expand_cache_key_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/cache.rb, line 79</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">expand_cache_key</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">namespace</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">expanded_cache_key</span> = <span class="ruby-identifier">namespace</span> <span class="ruby-operator">?</span> <span class="ruby-node">&quot;#{namespace}/&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-string">&quot;&quot;</span>

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">prefix</span> = <span class="ruby-constant">ENV</span>[<span class="ruby-string">&quot;RAILS_CACHE_ID&quot;</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">ENV</span>[<span class="ruby-string">&quot;RAILS_APP_VERSION&quot;</span>]
    <span class="ruby-identifier">expanded_cache_key</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;#{prefix}/&quot;</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">expanded_cache_key</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">retrieve_cache_key</span>(<span class="ruby-identifier">key</span>)
  <span class="ruby-identifier">expanded_cache_key</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-lookup_store">
            
              <b>lookup_store</b>(*store_option)
            
            <a href="Cache.html#method-c-lookup_store" name="method-c-lookup_store" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Creates a new CacheStore object according to the given options.</p>

<p>If no arguments are passed to this method, then a new <a
href="Cache/MemoryStore.html">ActiveSupport::Cache::MemoryStore</a> object
will be returned.</p>

<p>If you pass a <a href="../Symbol.html">Symbol</a> as the first argument,
then a corresponding cache store class under the <a
href="Cache.html">ActiveSupport::Cache</a> namespace will be created. For
example:</p>

<pre class="ruby"><span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">Cache</span>.<span class="ruby-identifier">lookup_store</span>(:<span class="ruby-identifier">memory_store</span>)
<span class="ruby-comment"># =&gt; returns a new ActiveSupport::Cache::MemoryStore object</span>

<span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">Cache</span>.<span class="ruby-identifier">lookup_store</span>(:<span class="ruby-identifier">mem_cache_store</span>)
<span class="ruby-comment"># =&gt; returns a new ActiveSupport::Cache::MemCacheStore object</span>
</pre>

<p>Any additional arguments will be passed to the corresponding cache store
class’s constructor:</p>

<pre class="ruby"><span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">Cache</span>.<span class="ruby-identifier">lookup_store</span>(:<span class="ruby-identifier">file_store</span>, <span class="ruby-string">'/tmp/cache'</span>)
<span class="ruby-comment"># =&gt; same as: ActiveSupport::Cache::FileStore.new('/tmp/cache')</span>
</pre>

<p>If the first argument is not a <a href="../Symbol.html">Symbol</a>, then it
will simply be returned:</p>

<pre class="ruby"><span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">Cache</span>.<span class="ruby-identifier">lookup_store</span>(<span class="ruby-constant">MyOwnCacheStore</span>.<span class="ruby-identifier">new</span>)
<span class="ruby-comment"># =&gt; returns MyOwnCacheStore.new</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-lookup_store_source')" id="l_method-c-lookup_store_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/3182295ce2fa01b02cb9af0b977a9cf83cc5d9aa/activesupport/lib/active_support/cache.rb#L54" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-lookup_store_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/cache.rb, line 54</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">lookup_store</span>(*<span class="ruby-identifier">store_option</span>)
  <span class="ruby-identifier">store</span>, *<span class="ruby-identifier">parameters</span> = *<span class="ruby-constant">Array</span>.<span class="ruby-identifier">wrap</span>(<span class="ruby-identifier">store_option</span>).<span class="ruby-identifier">flatten</span>

  <span class="ruby-keyword">case</span> <span class="ruby-identifier">store</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Symbol</span>
    <span class="ruby-identifier">retrieve_store_class</span>(<span class="ruby-identifier">store</span>).<span class="ruby-identifier">new</span>(*<span class="ruby-identifier">parameters</span>)
  <span class="ruby-keyword">when</span> <span class="ruby-keyword">nil</span>
    <span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">Cache</span><span class="ruby-operator">::</span><span class="ruby-constant">MemoryStore</span>.<span class="ruby-identifier">new</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">store</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                        </div>

    </div>
  </body>
</html>    